.<template>
  <el-dialog title="角色管理" :visible="showDialog" @close="offBtn">
    <el-checkbox-group v-model="checkList">
      <el-checkbox
        v-for="item in list"
        :key="item.id"
        :label="item.id"
      >{{ item.name }}</el-checkbox>
    </el-checkbox-group>
    <el-row slot="footer" type="flex" justify="center">
      <el-col :span="6">
        <el-button type="primary" size="small" @click="okBtn">确定</el-button>
        <el-button size="small" @click="offBtn">取消</el-button>
      </el-col>
    </el-row>
  </el-dialog>
</template>

<script>
import { roleListAPI } from '@/api/setting'
import { getUserDetail } from '@/api/user'
import { AssignemployeesRole } from '@/api/employees'
export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    userId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      list: [],
      checkList: []
    }
  },
  created() {
    this.roleListAPI()
  },
  methods: {
    //   确认按钮
    async okBtn() {
      //  发送请求
      await AssignemployeesRole({
        id: this.userId,
        roleIds: this.checkList
      })
      this.$message.success('操作成功')
      //  关闭窗口
      this.$emit('update:showDialog', false)
    },
    //   取消按钮
    offBtn() {
      this.$emit('update:showDialog', false)
    },
    //   获取全部角色列表
    async roleListAPI() {
      const { rows } = await roleListAPI({
        page: 1,
        pagesize: 999
      })
      // console.log(rows)
      this.list = rows
    },
    // 获取用户详情
    async getUserDetail(id) {
      const { roleIds } = await getUserDetail(id)
      //   console.log(res)
      this.checkList = roleIds
    }
  }
}
</script>

<style>

</style>
